package magic.deckbuilder;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class MagicDeckDBStructure extends SQLiteOpenHelper {
	
	public static final String TABLE_DECK = "table_deck";
	
	public static final String CREATE_DECK_TABLE = "CREATE TABLE " + TABLE_DECK + " ("
			+ Deck.ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " 
			+ Deck.TAG + " TEXT NOT NULL, " 
			+ Deck.RESUME + " TEXT" 	
			+ ") ";
	
	public static final String TABLE_CARD = "table_card";
	
	public static final String CREATE_CARD_TABLE = "CREATE TABLE " + TABLE_CARD + " ("
			+ Card.ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " 
			+ Card.NAME + " TEXT NOT NULL, " 
			+ Card.TYPE + " INTEGER NOT NULL, "
			+ Card.COLOR + " TEXT, "
			+ Card.CAPACITY + " TEXT, "
			+ Card.COST + " TEXT NOT NULL, "
			+ Card.PICTURE + " TEXT NOT NULL"
			+ ") ";
	
	public static final String TABLE_TYPE = "table_type";
	public static final String TYPE_ID = "id";
	public static final String TYPE_NAME = "name";	
	
	public static final String CREATE_TYPE_TABLE = "CREATE TABLE " + TABLE_TYPE + " ("
			+ TYPE_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " 
			+ TYPE_NAME + " TEXT NOT NULL"
			+ ") "; 

	public static final String TABLE_LIVRES = "table_livres";
	public static final String COL_ID = "ID";
	public static final String COL_ISBN = "ISBN";
	public static final String COL_TITRE = "Titre";
 
	public static final String CREATE_BDD = "CREATE TABLE " + TABLE_LIVRES + " ("
	+ COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + COL_ISBN + " TEXT NOT NULL, "
	+ COL_TITRE + " TEXT NOT NULL);";
 

	public MagicDeckDBStructure(Context context, String name, CursorFactory factory, int version) {
		super(context, name, factory, version);
		//Toast.makeText(context, CREATE_DB, Toast.LENGTH_LONG).show();
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
			//createDB(db);
		db.execSQL(CREATE_BDD);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		removeDB(db);
		onCreate(db);
	}
	
	private void removeDB(SQLiteDatabase db) {
		createDB(db, "DROP TABLE IF EXISTS");
	}
	
	private void createDB(SQLiteDatabase db) {
		createDB(db, "");
	}
	
	private void createDB(SQLiteDatabase db, String add) {
//		db.execSQL(CREATE_BDD);
//		db.execSQL(add + CREATE_DECK_TABLE);
//		db.execSQL(add + CREATE_CARD_TABLE);
//		db.execSQL(add + CREATE_TYPE_TABLE);
	}

}
